﻿using DotNetOpenAuth.AspNet.Clients;
using Inovout.Runtime;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using DotNetOpenAuth.Messaging;
using System.Net.Http;
using System.Net.Http.Headers;
using DotNetOpenAuth.AspNet;

namespace Inovout.Web.Security
{
    public class InovoutOAuthClient : BaseOAuth2Client
    {
        public static readonly string OAuth2ClientProviderName = "InovoutOAuth";
        public static readonly Dictionary<string, string> userDataMapping = new Dictionary<string, string> { 
        {"id", "user_identifier"},{"username", "name"},{"email", "email"}
        };

        public InovoutOAuthClient(string providerName)
            : this(providerName, ComponentRegistry.Resolve<IApplication>().Settings["ClientId"].ToString(),
                   ComponentRegistry.Resolve<IApplication>().Settings["ClientSecret"].ToString(),
            userDataMapping,
            ComponentRegistry.Resolve<IApplication>().Settings["AuthorizationEndpoint"].ToString(),
            ComponentRegistry.Resolve<IApplication>().Settings["TokenEndpoint"].ToString(),
            ComponentRegistry.Resolve<IApplication>().Settings["UserDataServiceEndpoint"].ToString())
        {
        }
        public InovoutOAuthClient()
            : this(OAuth2ClientProviderName,
                ComponentRegistry.Resolve<IApplication>().Settings["ClientId"].ToString(),
                ComponentRegistry.Resolve<IApplication>().Settings["ClientSecret"].ToString(),
            userDataMapping,
                ComponentRegistry.Resolve<IApplication>().Settings["AuthorizationEndpoint"].ToString(),
                ComponentRegistry.Resolve<IApplication>().Settings["TokenEndpoint"].ToString(),
                ComponentRegistry.Resolve<IApplication>().Settings["UserDataServiceEndpoint"].ToString()
                )
        {
        }

        public InovoutOAuthClient(string providerName, string clientId, string clientSecret,
                                    Dictionary<string, string> userDataMapping,
                                  string authorizeEndpoint, string tokenServiceEndpoint, string userDataServiceEndpoint,
                                   string scope = null)
            : base(providerName, clientId, clientSecret, userDataMapping, authorizeEndpoint, tokenServiceEndpoint, userDataServiceEndpoint,true, scope)
        {

        }

    }
}
